package com.ww.idiom.activity;

import net.youmi.android.diy.DiyManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.ww.core.activity.SlideMenuActivity;
import com.ww.core.util.CoreSharedPreferencesHelper;
import com.ww.core.util.DeviceUtil;
import com.ww.idiom.R;
import com.ww.idiom.activity.menu.LeftFragment;
import com.ww.idiom.db.IdiomDbHelper;

public class AboutActivity extends SlideMenuActivity implements OnClickListener {
	private Button fenxiang, pingfen, tuijian;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.activity_about, container, false);
		initView(view);
		return view;
	}

	private void initView(View view) {
		setTitle(view, LeftFragment.mTitleName);
		fenxiang = (Button) view.findViewById(R.id.fenxiang);
		fenxiang.setOnClickListener(this);
		pingfen = (Button) view.findViewById(R.id.pingfen);
		pingfen.setOnClickListener(this);
		tuijian = (Button) view.findViewById(R.id.tuijian);
		tuijian.setOnClickListener(this);
		TextView t = (TextView) view.findViewById(R.id.txt);
		String str = t.getText().toString();
		IdiomDbHelper w = new IdiomDbHelper(context);
		t.setText(str.replace("xxxx", w.getWordCount() + ""));

		CoreSharedPreferencesHelper h = new CoreSharedPreferencesHelper(context);
		String num = h.getValue("num");
		int count = 1;
		if (num != null) {
			count = Integer.parseInt(num);
		}
		h.setValue("num", (count+1)+"");

		if (count < 5) {
			tuijian.setVisibility(View.GONE);
		} else {
			tuijian.setVisibility(View.VISIBLE);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.pingfen:
			String str = "market://details?id=" + context.getPackageName();
			Intent localIntent = new Intent("android.intent.action.VIEW");
			localIntent.setData(Uri.parse(str));
			startActivity(localIntent);
			break;
		case R.id.fenxiang:
			DeviceUtil.share(context, context.getString(R.string.more_share), context.getString(R.string.txt_share),
					null);
			break;
		case R.id.tuijian:
			DiyManager.showRecommendWall(context);
			break;
		default:
			break;
		}
	}

}
